<?php
class model_index extends framework_base_model
{
	public static function getUserInfo($id){
		$sql = "SELECT `real_name`,`name_validate_flag` FROM `t_realinfo_validate` WHERE `user_id` = $id";
		$st = self::DB()->dbh->prepare($sql);
		$st->execute();
		$result1   = $st->fetch();
		$arr['real_name'] = $result1['name_validate_flag']?$result1['real_name']:$_SESSION['userInfo']['name'];
		$sql = "SELECT `amount`,`total_prize`,`point` FROM `t_user_amount` WHERE `user_id` = $id";
		$st = self::DB()->dbh->prepare($sql);
		$st->execute();
		$result2 = $st->fetch();
		$arr['amount'] = $result2['amount']?$result2['amount']:0;
		$arr['gold'] = $result2['total_prize']?$result2['total_prize']:0;
		$arr['point'] = $_SESSION['w_availPoints'];
	    $arr['msgcount'] = $_SESSION['w_messageCount'];
	    $arr['name'] = $_SESSION['userInfo']['name'];
		return $arr;
	}
	/**
	 * @author wangshui
	 * @descption 记录登录信息
	 * @param {int} user_id
	 * @return {undefined}
	*/
	public static function recordLoginInfo($user_id){
		$sql = "SELECT `login_count` FROM `t_user` WHERE `user_id` = $user_id";
		try {
		$st = self::DB()->dbh->prepare($sql);
		$st->execute();
		$result = $st->fetch();
		if($user_id){
			$real_ip = framework_static_base::real_ip();
			$data = array(
				'last_login_time'	=>date("Y-m-d H:i:s"),
				'last_login_ip'		=>$real_ip, 
				'login_count' 		=>$result['login_count'] + 1);
			self::db()->update('t_user', $data, '`user_id` = '.$user_id);
		}
		} catch(Exception $e) {
                framework_static_function::write_log('查询出错:'.json_encode($e->getMessage()), 'mysql_error');
                return false;
        }
	}
    /**查询track过期时间
     * @author zhanghaotian->chendeng
     * @date 2014.02.19
     * @descption 记录登录信息
     * @param $track
     * @return init
     */
    public static function get_cookie_expire($track){
        $sql = "
            SELECT
              cookie_time
            FROM
              t_channel_ad c,
              t_platform p
            WHERE
              c.track = :track
            AND
              c.platform_id = p.platform_id
        ";
        $stmt = self::DB() -> dbh -> prepare($sql);
        $stmt -> execute(array(":track"=>$track));
        return $stmt -> fetchColumn();
    }

}